package Huihu.src.Duoxiancheng;

public class Toy {
    public static void main(String[] args) {

        Produce produce=new Produce();

        new Thread(produce,"师傅").start();
    }
}

class Produce implements Runnable{

    private int top=1;

    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (top==20) {
                try {
                    eat(top);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            if (top>50){
                break;
            }
            System.out.println(Thread.currentThread().getName()+"生产了"+top+++"个玩具");
        }
    }

    public void eat(int i) throws InterruptedException {
        int j=1;
            while (true) {
                Thread.sleep(1000);
                System.out.println("吃了"+j+++"个馒头");
                if (j>3) {
                    break;
                }
        }
    }
}
